package org.yu.team2023.flashdays;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.SneakyThrows;
import net.minecraft.world.item.Rarity;


@Getter
@AllArgsConstructor
public enum TreasureQuality {
    COMMON(Rarity.COMMON, 2, 10, 1.3,6,0x6cfe75),UNCOMMON(Rarity.UNCOMMON,3,10,1.2,9,0x00F5FF), RARE(Rarity.RARE, 4, 10, 1.3,12,0xDA70D6), EPIC(Rarity.EPIC, 4, 10, 1.4,15,0xFFC125);
    private final Rarity rarity;
    private final int count;
    private final int startXp;
    private final double xpMulti;
    private final int maxLevel;
    private final int color;



    public static TreasureQuality saveValueOf(String key){
            try {
                return valueOf(key);
            }catch (Exception e){
                return TreasureQuality.COMMON;
            }
    }
    public static TreasureQuality indexOf(int index){
        if(index>TreasureQuality.values().length-1||index<0)return COMMON;
        return TreasureQuality.values()[index];
    }
    public static final Codec<TreasureQuality> CODEC= RecordCodecBuilder.create(ins->ins.group(Codec.INT.fieldOf("index").forGetter(TreasureQuality::ordinal)).apply(ins,TreasureQuality::indexOf));
}
